<?php defined('BASEPATH') or exit('No direct script access allowed');
class Transaction_m extends L_Model
{
	public function __construct(){	
		parent::__construct();
	}
	
	public function add_one_transaction($data) {
		$default_dbprefix = $this->db->dbprefix;
		$this->db->dbprefix='l_';
		$result = $this->db->insert('transaction', $data);
		$this->db->dbprefix = $default_dbprefix;
		return $this->db->insert_id();
	}
	
	public function deposit($user_id, $amount) {
		$now=new DateTime();
		$this->add_one_transaction(array(
	    	'user_id' => $user_id,
	        'trans_type' => 'DEPOSIT',
			'win_lose' => $amount,
			'stake' => 0,
			'status' => 'COMPLETED',
	        'trans_date' => $now->format('Y-m-d H:i:s'),
	        'settle_date' => $now->format('Y-m-d H:i:s')));
	}
	
	public function withdraw($user_id, $amount) {
		$now=new DateTime();
		$this->add_one_transaction(array(
	    	'user_id' => $user_id,
	        'trans_type' => 'WITHDRAW',
			'win_lose' => 0,
			'stake' => $amount,
			'status' => 'COMPLETED',
	        'trans_date' => $now->format('Y-m-d H:i:s'),
	        'settle_date' => $now->format('Y-m-d H:i:s')));
	}
}